#pragma once

#include <cstdio>
#include <iostream>
#include <string>
#include <thread>

#define none         "\033[0m"
#define black        "\033[0;30m"  
#define dark_gray    "\033[1;30m"  
#define blue         "\033[0;34m"  
#define light_blue   "\033[1;34m"  
#define green        "\033[0;32m"  
#define light_green  "\033[1;32m"  
#define cyan         "\033[0;36m"  
#define light_cyan   "\033[1;36m"  
#define red          "\033[0;31m"  
#define light_red    "\033[1;31m"  
#define purple       "\033[0;35m"  
#define light_purple "\033[1;35m"  
#define brown        "\033[0;33m"  
#define yellow       "\033[1;33m"  
#define light_gray   "\033[0;37m"  
#define white        "\033[1;37m"  


class task
{
public:
    task()
    {}
    task(int x, int y, char op) : _x(x), _y(y), _op(op), _res(0), _st(NORMAL)
    {}
    ~task()
    {}

    int operator()()
    {
        switch (_op) {
            case '+': _res = _x + _y; break;
            case '-': _res = _x - _y; break;
            case '*': _res = _x * _y; break;
            case '/':
                if (_y == 0) _st = ERROR;
                else         _res = _x / _y;
                break;
            default: _st = ERROR; break;
        }
        std::this_thread::sleep_for(std::chrono::microseconds(200));
        return _res;
    }

    void print_expression()
    {
        char buff[64];
        snprintf(buff, 64, blue "%d %c %d = ?" none, _x, _op, _y);
        std::cout << buff << std::endl;
    }

    void print_result()
    {
        char buff[64];
        if (_st == ERROR)
            snprintf(buff, 64, light_red "%d %c %d = ? (logic error)" none, _x, _op, _y);
        else
            snprintf(buff, 64, green "%d %c %d = %d" none, _x, _op, _y, _res);
        std::cout << buff << std::endl;
    }

private:
    enum status_t 
    {
        NORMAL = 0,
        ERROR,
    };

private:
    int _x;
    int _y;
    char _op;
    int _res;
    int _st;
};
